import Vue from "vue";
import { Toast } from 'vant';
import { Notify as $Notify } from 'vant';

export default class Notify {

    /**
     * 实例对象
     *
     * @private
     * @static
     * @memberof Notify
     */
    private static notify: any;

    /**
     * vue 实例
     *
     * @private
     * @type {Vue}
     * @memberof Notify
     */
    private vm!: Vue;


    /**
     * 单例构造函数
     * 
     * @memberof Notify
     */
    private constructor() {
        if (Notify.notify) {
            return Notify.notify;
        }
    }

    /**
     * 静态获取单例对象方法
     *
     * @static
     * @returns {Notify}
     * @memberof Notify
     */
    public static getInstance(): Notify {
        if (!Notify.notify) {
            Notify.notify = new Notify();
        }
        return Notify.notify;
    }

    /**
     * 打开消息通知
     *
     * @param {{ mode: string, options: { position?: string, icon?: string, type: any, message: string } }} props
     * mode:消息通知模式 position:消息通知位置 icon:自定义图标，支持传入图标名称或图片链接 type:消息通知类型 message:通知信息
     * mode为notify时，type为{primary、success、warning、danger}
     * mode为success、fail和其他时，position为{top、bottom、middle}
     * @memberof Notify
     */
    public openNotify(props: { mode: string, options: { position?: string, icon?: string, type: any, message: string } }) {
        if (Object.is(props.mode,'success')) {
            Toast.success(props.options);
        } else if (Object.is(props.mode,'fail')) {
            Toast.fail(props.options);
        } else if (Object.is(props.mode,'notify')) {
            $Notify(props.options);
        } else {
            Toast(props.options);
        }
    }

}